﻿//    HexagonMine
//    Copyright (c) 2009-2010 BenBear
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.

#ifndef __HEXAGON_MINE_CANVAS_H__
#define __HEXAGON_MINE_CANVAS_H__

#pragma once

#include "HexagonMineGame.h"

class CHexagonMineCanvas :
	public UiCanvas,
	public hexagon_mine::IGameShowObserver
{
	int m_CenterWidth;
	int m_CenterHeight;

	int m_HoleRadius;

	int X_ADJUST;
	int Y_ADJUST;

	int m_DownHoleX;
	int m_DownHoleY;
	int m_DownTick;

	hexagon_mine::CHexagonMineGame* m_Game;

public:
	CHexagonMineCanvas();
	~CHexagonMineCanvas();

	void Init(hexagon_mine::CHexagonMineGame* game);

public:
	// 将屏幕坐标 (x, y) 转换为蜂窝坐标
	// 返回值表示该坐标是否离圆心足够近
	bool ConvertXYToHexagon(int x, int y, int& hexagon_x, int& hexagon_y) const;

	bool SetDownHexagonXY(int x, int y);

	void UpdateHole(int hexagon_x, int hexagon_y);
	void UpdateDownHole();

private:
	void DrawHole(int hexagon_x, int hexagon_y, int value, hexagon_mine::HOLE_STATUS status);
	void DrawSign(hexagon_mine::HOLE_STATUS status, RECT rc);

	void GetHexagonHoleCenter(int hexagon_x, int hexagon_y, int& x, int& y) const;

protected:
	virtual void Init(int num_width, int num_y, bool horizontal, bool left_side, bool right_side);
	virtual void Update(const std::vector<hexagon_mine::IGameShowObserver::HoleInfo>& holes);
};

#endif
